package com.example.shirodemo.config.exception;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @author 绫小路
 * @date 2021/1/3 23:11
 * @description
 */
@Configuration
public class ErrorPageConfig implements ErrorPageRegistrar {

  @Override
  public void registerErrorPages(ErrorPageRegistry registry) {
    ErrorPage[] errorPages = new ErrorPage[2];
    //发生页面找不到错误时，会访问到路径"/error/404" 再编写一个自己个controller控制即可！
    errorPages[0] = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
    errorPages[1] = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401");
//    errorPages[1] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500");
    registry.addErrorPages(errorPages);
  }
}
